/*
 *  $Id: Queue.cs 1217 2010-11-27 10:48:54Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System.Collections.Generic;

using Nereal.Serialization;

namespace Ragima.Events {
    /// <summary>
    /// Очередь игровых событий.
    /// </summary>
    [XmlRootName("queue")]
    public class EventQueue {
        [Serialize, XmlName("events", "event")]
        private readonly List<AbstractEvent> _events;

        public EventQueue() {
            _events = new List<AbstractEvent>();
        }

        public bool Empty {
            get { return _events.Count == 0; }
        }

        public void Enqueue(AbstractEvent ev) {
            _events.Add(ev);
        }

        public AbstractEvent Dequeue() {
            if (Empty)
                return null;
            var i = _events.Count - 1;
            var ev = _events[i];
            _events.RemoveAt(i);
            return ev;
        }
    }
}
